package com.lanou.lenanapp.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.lenanapp.R;


public class SplashActivity extends Activity implements View.OnClickListener {
    private ImageView imageIv;
    private TextView fristtitle, belowtitle;
    private Handler handler;
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            isIntent();
        }
    };




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        imageIv = (ImageView) findViewById(R.id.imageIv);
        imageIv.setOnClickListener(this);

        fristtitle = (TextView) findViewById(R.id.fristtitle);
        belowtitle = (TextView) findViewById(R.id.belowtitle);
        handler = new Handler();
        handler.postDelayed(runnable, 8000);

        animatorStart();
    }

    /**
     * 动画的播放
     **/
    private void animatorStart() {
        //图片的消失
        ObjectAnimator animator = new ObjectAnimator().ofFloat(imageIv, "alpha", 1f, 0f);
        animator.setDuration(8000);
        animator.start();
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                imageIv.setVisibility(View.GONE);
            }
        });
        //字的消失
        ObjectAnimator animator1 = new ObjectAnimator().ofFloat(fristtitle, "translationY", 0f, 1100f);
        animator1.setDuration(8000).setStartDelay(400);
        animator1.setInterpolator(new BounceInterpolator());//弹跳效果
        animator1.start();
        animator1.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                fristtitle.setVisibility(View.GONE);
            }
        });
        ObjectAnimator animator2 = new ObjectAnimator().ofFloat(belowtitle, "translationY", 0f, 1000f);
        animator2.setDuration(8000);
        animator2.setInterpolator(new BounceInterpolator());
        animator2.start();
        animator2.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                belowtitle.setVisibility(View.GONE);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageIv:
                isIntent();//点击图片立即跳转
                handler.removeCallbacks(runnable);//关闭handler
                break;
        }

    }

    //跳转的方法
    private void isIntent() {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
        this.finish();
    }


}
